package sg.edu.nus.iss.billing.gui.subscription;

import static sg.edu.nus.iss.billing.localization.MessageKeyManager.getMessage;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import sg.edu.nus.iss.billing.entity.RecordState;
import sg.edu.nus.iss.billing.entity.service.CableTVService;
import sg.edu.nus.iss.billing.entity.service.DigitalVoiceService;
import sg.edu.nus.iss.billing.entity.service.MobileVoiceService;
import sg.edu.nus.iss.billing.localization.MessageKeyManager;

/**
 * 
 * @author RAJU NAVANEETHAM VENKATESHWARI
 *
 */
public class AddSubscriptionPanel extends TabSubscriptionPanel {

	private static final long serialVersionUID = -2426196686689237208L;
	
	

	public AddSubscriptionPanel() {

		super();
		
	}

	@Override
	public SubcriptionPanel createMobilePlanPanel() {

		if (isSubscribeMobile() || cust.getActive() != RecordState.ACTIVE) {
			return null;
		}
			return new SubcriptionPanel(accNo, new MobileVoiceService());
	}

	@Override
	public SubcriptionPanel createDigitalPlanPanel() {

		if (isSubscribeDigitalVoice()  || cust.getActive() != RecordState.ACTIVE) {
			return null;
		}
		return new SubcriptionPanel(accNo, new DigitalVoiceService());
	}

	@Override
	public SubcriptionPanel creaetCablePlanPanel() {

		if (isSubscribeCableTV()  || cust.getActive() != RecordState.ACTIVE) {
			return null;
		}
		return new SubcriptionPanel(accNo, new CableTVService());
	}

	@Override
	public JPanel createActionButtonsPanel() {

		// Add event latter
		JPanel actionPanel = new JPanel(new FlowLayout());
		JButton regBtn = new JButton();
		actionPanel.add(regBtn);
		regBtn.setText(getMessage("subs.action.register"));
		regBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				
				int opt= JOptionPane.showConfirmDialog(null, MessageKeyManager.getMessage("msg.subs.subscribe"));
				if (opt == JOptionPane.YES_OPTION){
					if(currentSelectedPanel instanceof SubcriptionPanel) {
						if(currentSelectedPanel.subscribePlan()){
							refreshBottomPanel();
							JOptionPane.showMessageDialog(null,  getMessage("msg.subs.subscribe.success"), null,JOptionPane.INFORMATION_MESSAGE);
						}
					}
				}else{
					return;
				}
				
				
			}
		});

		JButton cancelBtn = new JButton();
		cancelBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int opt= JOptionPane.showConfirmDialog(null, MessageKeyManager.getMessage("msg.subs.cancel"));
				if (opt == JOptionPane.YES_OPTION){
					refreshBottomPanel();
				}else{
					return;
				}
			}
		});
		actionPanel.add(cancelBtn);
		cancelBtn.setText(getMessage("action.cancel"));
		actionPanel.setVisible(false);
		return actionPanel;
	}

}
